from dataclasses import dataclass
from typing import Tuple, List


@dataclass(frozen=True)
class EnvConfig:
    # 当前环境：'DEV' or 'PRD'
    ENV: str = 'PRD'  # 修改为 'PRD' 即为生产环境

    @property
    def IS_DEV(self) -> bool:
        return self.ENV.upper() == 'DEV'

    @property
    def IS_PRD(self) -> bool:
        return self.ENV.upper() == 'PRD'

@dataclass(frozen=True)
class AppInfo:
    NAME: str = "AutoGET店铺数据工具"
    VERSION: str = "1.0"
    AUTHOR: str = "liujia8080"
    ORGANIZATION: str = "轻松工坊EasyStudio"
    DATATYPE: List[str] = ("昨日", "7日", "30日")

@dataclass(frozen=True)
class PathConfig:
    BASE_DIR: str = "."  # 当前工作目录
    LOG_FILE: str = "logs/app_main.log"
    DB_FILE: str = "db/appdata.db"
    DEFAULT_EXPORT_DIR: str = "exports"
    DOWNLOAD_DIR: str = "download"
    OCR_DIR: str = "download/ocr"
    TESSERACT_EXE: str = "tesseract.exe"
    W64: str = "https://www.myluckyai.cn/download/tesseract-ocr-w64-setup-v5.0.0.20211201.exe"
    W32: str = "https://www.myluckyai.cn/download/tesseract-ocr-w32-setup-v5.0.0.20211201.exe"

@dataclass(frozen=True)
class UIConfig:
    MAIN_WINDOW_WIDTH: int = 1200
    MAIN_WINDOW_HEIGHT: int = 800

@dataclass(frozen=True)
class DBConfig:
    DB_NAME: str = "appdata.db"
    STORE_TABLE: str = "stores"
    PRODUCT_TABLE: str = "products"
    STORE_DATA_TABLE: str = "stores_data"
    PRODUCT_DATA_TABLE: str = "products_data"
    # 字段名到中文的映射
    COLUMN_NAME_MAP = {
        'fetch_date': '获取日期',
        'data_type': '数据类型',
        'store_name': '店铺名称',
        'description': '商品描述',
        'product_id': '商品ID',
        'store_uv': '店铺访客数',
        'store_pv': '店铺浏览量',
        'product_uv': '商品访客数',
        'product_pv': '商品浏览量',
        'revenue': '成交金额',
        'orders': '成交订单数',
        'buyers': '成交买家数',
        'conversion_rate': '成交转化率',
        'avg_order_value': '成交UV价值',
        'uv_value': 'UV价值',
        'date_range': '日期范围',
        'items_sold': '成交件数'
    }

@dataclass(frozen=True)
class LogConfig:
    LOG_DIR: str = "logs"
    LOG_NAME: str = "app_main"
    LOG_LEVEL: str = "INFO"  # 可选 DEBUG/INFO/WARNING/ERROR
    ENCODING: str = "utf-8"
    MAX_LINES: int = 1000 #读取日志文件最后1000行

@dataclass(frozen=True)
class ChromeConfig:
    EXECUTABLE_PATH: str = "C:/Program Files/Google/Chrome/Application/chrome.exe"
    DEBUGGING_PORT: int = 9333
    CDP_URL: str = 'http://127.0.0.1:9333'
    START_CHROME: str = '--remote-debugging-port=9333'
    USER_DATA_DIR: str = 'chrome_user_data'
    PDD_LLSJ_URL: str = 'https://mms.pinduoduo.com/sycm/search_data/plate'
    PDD_SPGK_URL: str = 'https://mms.pinduoduo.com/sycm/goods_effect?msfrom=mms_sidenav'
    PDD_LOGIN_URL: str = 'https://mms.pinduoduo.com/login/'

@dataclass(frozen=True)
class BusinessConfig:
    SITE_URL: str = (
        "http://127.0.0.1:8000/check_login_code"
        if EnvConfig.ENV == "DEV"
        else "https://www.myluckyai.cn/check_login_code"
    )



# 设置环境配置对象
Env = EnvConfig()
# 最终统一导出接口
class AppConfig:
    Env = Env
    AppInfo = AppInfo
    Path = PathConfig
    UI = UIConfig
    DB = DBConfig
    Log = LogConfig
    Chrome = ChromeConfig
    Business = BusinessConfig
